﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.BLL;
using CMS.BLL.Entity;
using System.Net;
using System.IO; 
public partial class Controls_Common_ctrLiveSupport : System.Web.UI.UserControl
{
    private int nCurrentLanguage = Support.GetCurrentLanguage();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            
            this.InitData();
            BindData();
            BindDataDepHCM();
            BindDataDepHN();
        }
    }
  

    private void InitData()
    { 
        int nCurentLang = Support.GetCurrentLanguage ();
       
        lblHanoi.Text = MultipleLanguage.BRACH1[nCurentLang - 1].Replace("Văn phòng", "").Replace("Head","");
        lblHCM.Text = MultipleLanguage.BRACH2[nCurentLang - 1].Replace("Văn phòng", "").Replace("Branch", ""); ;
    
        lblSale1_Banch1.Text   = MultipleLanguage.SUPPORT_SALE[nCurentLang - 1];
        lblSale2_Banch1.Text = MultipleLanguage.SUPPORT_TECH [nCurentLang - 1];
        lblSale1_Banch2.Text = MultipleLanguage.SUPPORT_SALE[nCurentLang - 1];
        lblSale2_Banch2.Text = MultipleLanguage.SUPPORT_TECH[nCurentLang - 1];

    }

    private void BindData()
    {
        ContactOffice objContactOffice = new ContactOffice();
        DataTable dtbContactOffice =  objContactOffice.Search();
        lblEmailHN.Text = "<b>Email:</b>" + " " + ConvertData.ConvertToString(dtbContactOffice.Rows[0]["Email"]);
        lblEmailHCM.Text = "<b>Email:</b>" + " " + ConvertData.ConvertToString(dtbContactOffice.Rows[1]["Email"]);
        switch (nCurrentLanguage )
        {
            case 1:
                lblAddressHN.Text = "<b>Địa chỉ:</b>" + " " + ConvertData.ConvertToString(dtbContactOffice.Rows[0]["Address1"]);
                lblAddressHCM.Text = "<b>Địa chỉ:</b>" + " " + ConvertData.ConvertToString(dtbContactOffice.Rows[1]["Address1"]);
               
                lblFaxHCM.Text ="<b>Fax:</b>" + " " + ConvertData.ConvertToString(dtbContactOffice.Rows[1]["Fax1"]);
                lblFaxHN.Text ="<b>Fax:</b>" + " " + ConvertData.ConvertToString(dtbContactOffice.Rows[0]["Fax1"]);
                lblTelHN.Text = "<b>Tel:</b>" + " " + ConvertData.ConvertToString(dtbContactOffice.Rows[0]["Tel1"]);
                lblTelHCM.Text = "<b>Tel:</b>" + " " + ConvertData.ConvertToString(dtbContactOffice.Rows[1]["Tel1"]);
                break;
            case 2:
                lblAddressHN.Text = "<b>Address:</b>" + " " + ConvertData.ConvertToString(dtbContactOffice.Rows[0]["Address2"]);
                lblAddressHCM.Text = "<b>Address:</b>" + " " + ConvertData.ConvertToString(dtbContactOffice.Rows[1]["Address2"]);
              
                lblFaxHCM.Text ="<b>Fax:</b>" + " " + ConvertData.ConvertToString(dtbContactOffice.Rows[1]["Fax2"]);
                lblFaxHN.Text ="<b>Fax:</b>" + " " + ConvertData.ConvertToString(dtbContactOffice.Rows[0]["Fax2"]);
                lblTelHN.Text = "<b>Tel:</b>" + " " + ConvertData.ConvertToString(dtbContactOffice.Rows[0]["Tel2"]);
                lblTelHCM.Text = "<b>Tel:</b>" + " " + ConvertData.ConvertToString(dtbContactOffice.Rows[1]["Tel2"]);
                break;
            case 3:
                lblAddressHN.Text = ConvertData.ConvertToString(dtbContactOffice.Rows[0]["Address3"]);
                lblAddressHCM.Text = ConvertData.ConvertToString(dtbContactOffice.Rows[1]["Address3"]);

                  lblFaxHCM.Text ="<b>Fax:</b>" + " " + ConvertData.ConvertToString(dtbContactOffice.Rows[1]["Fax3"]);
                lblFaxHN.Text ="<b>Fax:</b>" + " " + ConvertData.ConvertToString(dtbContactOffice.Rows[0]["Fax3"]);
                lblTelHN.Text = "<b>Tel:</b>" + " " + ConvertData.ConvertToString(dtbContactOffice.Rows[0]["Tel3"]);
                lblTelHCM.Text = "<b>Tel:</b>" + " " + ConvertData.ConvertToString(dtbContactOffice.Rows[1]["Tel3"]);
                break;
        }
          

            Company objCompany = new Company();
            DataTable dtbCompany = new DataTable();
            dtbCompany = objCompany.Search();
            int nCompanyCount = dtbCompany.Rows.Count;
            int nCompanyLastestID = ConvertData.ConvertToInt(dtbCompany.Rows[nCompanyCount - 1]["CompanyID"]);
            objCompany.LoadById(nCompanyLastestID);

           

            ltrYahoo1.Text = "<a href=\"ymsgr:sendim?" + objCompany.Data.YahooAccount1  + "\"" +  "style=\"text-decoration: none;color: #FFF;\" class=\"notetext\"> <img src=\"http://opi.yahoo.com/online?u=" + objCompany.Data.YahooAccount1 + "&m=g&t=1&l=us\" border=\"0\" />&nbsp;<span style=\"color:black; font-weight:bold\"></span></a>";
            ltrYahoo2.Text = "<a href=\"ymsgr:sendim?" + objCompany.Data.YahooAccount2 + "\"" + "style=\"text-decoration: none;color: #FFF;\" class=\"notetext\"> <img src=\"http://opi.yahoo.com/online?u=" + objCompany.Data.YahooAccount2 + "&m=g&t=1&l=us\" border=\"0\" />&nbsp;<span style=\"color:black; font-weight:bold\"></span></a>";

            ltrYahoo3.Text = "<a href=\"ymsgr:sendim?" + objCompany.Data.YahooAccount3 + "\"" + "style=\"text-decoration: none;color: #FFF;\" class=\"notetext\"> <img src=\"http://opi.yahoo.com/online?u=" + objCompany.Data.YahooAccount3 + "&m=g&t=1&l=us\" border=\"0\" />&nbsp;<span style=\"color:black; font-weight:bold\"></span></a>";
            ltrYahoo4.Text = "<a href=\"ymsgr:sendim?" + objCompany.Data.YahooAccount4 + "\"" + "style=\"text-decoration: none;color: #FFF;\" class=\"notetext\"> <img src=\"http://opi.yahoo.com/online?u=" + objCompany.Data.YahooAccount4 + "&m=g&t=1&l=us\" border=\"0\" />&nbsp;<span style=\"color:black; font-weight:bold\"></span></a>";

            //BindDataToHN();
            //BindDataToHCM(); 
    }

    //private void BindDataToHN()
    //{
        //ContactHotline objHotline = new ContactHotline();
        //DataTable dtbHotline = new DataTable();
        //dtbHotline = objHotline.Search(1);
        //rptHotlineHN.DataSource = dtbHotline;
        //rptHotlineHN.DataBind();
    //}
    //private void BindDataToHCM()
    //{
        //ContactHotline objHotline = new ContactHotline();
        //DataTable dtbHotline = new DataTable();
        //dtbHotline = objHotline.Search(2);
        //rptHotlineHCM .DataSource = dtbHotline;
        //rptHotlineHCM.DataBind();
    //}

    protected void rptHotlineHN_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label lblHotlineHN = (Label)e.Item.FindControl("lblHotlineHN");
            switch (nCurrentLanguage)
            { 
                case 1:
                    lblHotlineHN.Text = "Hotline: " + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "HotlineNumber1")); 
                    break;
                case 2:
                    lblHotlineHN.Text = "Hotline: " + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "HotlineNumber2")); 
                    break;
                case 3:
                    lblHotlineHN.Text = "Hotline: " + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "HotlineNumber3")); 
                    break;
            }
            
        }
    }
    protected void rptHotlineHCM_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {

            Label lblHotlineHN = (Label)e.Item.FindControl("lblHotlineHCM");
            switch (nCurrentLanguage)
            {
                case 1:
                    lblHotlineHN.Text = "Hotline: " + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "HotlineNumber1"));
                    break;
                case 2:
                    lblHotlineHN.Text = "Hotline: " + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "HotlineNumber2"));
                    break;
                case 3:
                    lblHotlineHN.Text = "Hotline: " + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "HotlineNumber3"));
                    break;
            }
        }
    }

    private void BindDataDepHN()
    {
        ContactDepartment obj = new ContactDepartment();
        DataTable dtb = new DataTable();
        dtb = obj.Search(1);
        int nCount = dtb.Rows.Count;
        if (nCount > 0)
        {
            rptDepHN.Visible = true;
            rptDepHN.DataSource = dtb;
            rptDepHN.DataBind(); 
        }
        else
        {
            rptDepHN.Visible = false;
        }
    }

    private void BindDataDepHCM()
    {
        ContactDepartment obj = new ContactDepartment();
        DataTable dtb = new DataTable();
        dtb = obj.Search(2);
        int nCount = dtb.Rows.Count;
        if (nCount > 0)
        {
            rptDepHCM .Visible = true;
            rptDepHCM.DataSource = dtb;
            rptDepHCM.DataBind();
        }
        else
        {
            rptDepHCM.Visible = false;
        }
    }
    protected void rptDepHN_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
             Label lblDepNameHN = (Label)e.Item.FindControl("lblDepNameHN");
             Label lblDepTelHN = (Label)e.Item.FindControl("lblDepTelHN");
             Label lblDepEmailHN = (Label)e.Item.FindControl("lblDepEmailHN");
             lblDepEmailHN.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Email"));
            
             switch (nCurrentLanguage)
             {
                 case 1:
                     lblDepNameHN.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "DepartmentName1"));
                     lblDepTelHN.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Tel1"));
                     break;
                 case 2:
                     lblDepNameHN.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "DepartmentName2"));
                     lblDepTelHN.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Tel2"));
                     break;
                 case 3:
                     lblDepNameHN.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "DepartmentName3"));
                     lblDepTelHN.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Tel3"));
                     break;
             } 
            
        }
    }
    protected void rptDepHCM_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label lblDepNameHCM = (Label)e.Item.FindControl("lblDepNameHCM");
            Label lblDepTelHCM = (Label)e.Item.FindControl("lblDepTelHCM");
            Label lblDepEmailHCM = (Label)e.Item.FindControl("lblDepEmailHCM");
            lblDepEmailHCM.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Email"));

            switch (nCurrentLanguage)
            {
                case 1:
                    lblDepNameHCM.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "DepartmentName1"));
                    lblDepTelHCM.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Tel1"));
                    break;
                case 2:
                    lblDepNameHCM.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "DepartmentName2"));
                    lblDepTelHCM.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Tel2"));
                    break;
                case 3:
                    lblDepNameHCM.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "DepartmentName3"));
                    lblDepTelHCM.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Tel3"));
                    break;
            } 
        }
    }
}